package com.hzit.servlet;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.hzit.entity.Classes;
import com.hzit.entity.PageResult;
import com.hzit.service.ClassesService;
import com.hzit.service.StudentService;
import com.hzit.service.impl.ClassesServiceImpl;
import com.hzit.service.impl.StudentServiceImpl;
import com.hzit.vo.StudentVo;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
	private ClassesService classesService ;
	@SneakyThrows
	@Override
	public void init() throws ServletException {
		classesService = new ClassesServiceImpl();
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//1. 处理post请求的中文乱码
		req.setCharacterEncoding("UTF-8");
		//2. 设置响应到浏览器的显示的数据格式
		resp.setContentType("text/html;charset=utf8");
		//3 查询出所有学生
		List<Classes> classes = classesService.findAll();
		//2.2 将学生转换为json对象
		String s = JSON.toJSONString(classes);
		//2.3 将学生信息发送到页面
		resp.getWriter().println(s);
		resp.getWriter().flush();
	}


}
